﻿Public Class dlgAreaCircSource

    Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        Dim AreaCircSource(-1) As CAermod.AreaCircSource
        AreaCircSource = Me.m_BaseSoruce
        ReDim Preserve AreaCircSource(AreaCircSource.Length)
        AreaCircSource(AreaCircSource.Length - 1) = New CAermod.AreaCircSource
        ReDim AreaCircSource(AreaCircSource.Length - 1).PollutionPara(Me.m_ArrayPollut.Length - 1) '设置新增加的污染源的污染物的类型
        AreaCircSource(AreaCircSource.Length - 1).PollutionPara(Me.m_ArrayPollut.Length - 1) = New CAermod.PollutionPara
        AreaCircSource(AreaCircSource.Length - 1).SetPollutePara(AermodProject0.Aermod.Control.AllPolluts)
        '刷新数据
        AreaCircSource(AreaCircSource.Length - 1).Location.Srcid = "AC" & (Me.m_SourceCount + 1)
        Me.m_SourceCount += 1
        AreaCircSource(AreaCircSource.Length - 1).SourceName = "圆形面源" & Me.m_SourceCount '污染源名称

        Me.m_BaseSoruce = AreaCircSource
        ''修改列表
        Me.ListPolute.Items.Add(AreaCircSource(AreaCircSource.Length - 1).SourceName)
        ListPolute.SelectedIndex = ListPolute.Items.Count - 1
    End Sub

    Private Sub txtRelhgt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRelhgt.TextChanged

    End Sub

    Private Sub txtRelhgt_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtRelhgt.Validating
        Dim i As Integer
        For i = 0 To Me.ListPolute.SelectedItems.Count - 1
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaCircSource).Relhgt = Me.txtRelhgt.Value
        Next
    End Sub

    Private Sub txtNverts_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtNverts.Validating
        Dim i As Integer
        For i = 0 To Me.ListPolute.SelectedItems.Count - 1
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaCircSource).Nverts = Me.txtNverts.Value
        Next
    End Sub

    Private Sub txtRadius_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtRadius.Validating
        Dim i As Integer
        For i = 0 To Me.ListPolute.SelectedItems.Count - 1
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaCircSource).Radius = Me.txtRadius.Value
        Next
    End Sub

    Private Sub txtSzinit_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtSzinit.Validating
        Dim i As Integer
        For i = 0 To Me.ListPolute.SelectedItems.Count - 1
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaCircSource).Szinit = Me.txtSzinit.Value
        Next
    End Sub

    Private Sub ListPolute_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListPolute.SelectedIndexChanged
        If Me.ListPolute.SelectedIndex >= 0 Then
            Me.txtRelhgt.Value = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaCircSource).Relhgt
            Me.txtSzinit.Value = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaCircSource).Szinit
            Me.txtNverts.Value = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaCircSource).Nverts
            Me.txtRadius.Value = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaCircSource).Radius
            Me.cmbPolluteUnit.Text = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaCircSource).PolluteUnit

        End If
    End Sub

    Private Sub dlgAreaCircSource_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.EFlexEmisFact.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.EFlexMethod1.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.EFlexSourceNameAndS.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.EFlexSourceNameAndS.SetData(0, 1, "排放速率")

        Me.EFlexEmisFact.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexEmisFact.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexEmisFact.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None

        Me.EFlexMethod1.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexMethod1.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexMethod1.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None

        Me.EFlexSourceNameAndS.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexSourceNameAndS.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexSourceNameAndS.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDel.Click
        Dim iSelected As Integer = ListPolute.SelectedIndex
        If iSelected >= 0 Then
            Dim AreaCircSources(-1) As CAermod.AreaCircSource
            AreaCircSources = Me.m_BaseSoruce
            If iSelected <= ListPolute.Items.Count - 2 Then
                For i As Integer = iSelected To ListPolute.Items.Count - 2
                    AreaCircSources(i) = AreaCircSources(i + 1)

                Next
            End If
            ReDim Preserve AreaCircSources(AreaCircSources.Length - 2)
            ListPolute.Items.Clear()
            For i As Integer = 0 To AreaCircSources.Length - 1
                ListPolute.Items.Add(AreaCircSources(i).SourceName)
            Next
            If ListPolute.Items.Count > 0 Then
                If iSelected <= ListPolute.Items.Count - 1 Then
                    ListPolute.SelectedIndex = iSelected
                Else
                    ListPolute.SelectedIndex = iSelected - 1
                End If
            End If

            Me.m_BaseSoruce = AreaCircSources
        End If
    End Sub

    Private Sub cmbPolluteUnit_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPolluteUnit.SelectedIndexChanged
        Dim i As Integer
        For i = 0 To Me.ListPolute.SelectedItems.Count - 1
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaCircSource).PolluteUnit = Me.cmbPolluteUnit.Text
        Next
    End Sub
    Public Sub Modify()
        Dim p As New Point
        p.X = Me.Location.X
        p.Y = Me.UltraTabControl3.Location.Y
        Me.UltraTabControl3.Location = p
        Me.cmdAdd.Visible = False
        Me.cmdDel.Visible = False
        Me.Width = 500
    End Sub


End Class
